﻿using System;
namespace Medianamik.Core.Interfaces
{
    public interface ILock
    {
        DateTime? ActivationDate { get; set; }
        DateTime? LastCall { get; set; }
        Guid LockId { get; set; }
        Guid LockObject { get; set; }
        DateTime? NextCall { get; set; }
        Guid Transaction { get; set; }
        int Ultimatum { get; set; }
        string UserInfo { get; set; }
    }

    public static class ILockExtensions
    {
        public static bool IsActive(this ILock pLock )
        {
            return pLock.ActivationDate.HasValue;
        }

        public static bool IsElapsed(this ILock pLock)
        {
            return pLock.IsActive()
                    && pLock.ActivationDate.Value.AddSeconds(pLock.Ultimatum) < DateTime.Now;
           
        }

        public static bool IsAlive(this ILock pLock)
        {
           return pLock.IsActive() && !pLock.IsElapsed();
        }
    }

}
